//#include "dir.h"
#include"threadPool.h"
int Mkdir(int netfd,char* addr,char * dirname)
{
    //printf("addr = %s\n",addr);
    int ret = mkdir(addr,0777);
    NETDESK_LOG_INFO(dirname,"mkdir");
    train_t train;
    bzero(&train,sizeof(train));
    if(ret == -1)
    {
        sprintf(train.data,"mkdir: 无法创建目录 \"%s\": 文件已存在",dirname);
        train.length = strlen(train.data);
        send(netfd, &train, sizeof(int) + train.length, MSG_NOSIGNAL);
        //printf("sasas\n");
        //  char buf[50]="error:mkdir failed!";
        NETDESK_LOG_DEBUG(dirname,"mkdir");
        // //send(netfd,buf,strlen(buf),0);
        // send(netfd,"mkdir",5,0);
        // send(netfd,buf,strlen(buf),0);

    }
    else 
    {
        send(netfd, &train, sizeof(int) + train.length, MSG_NOSIGNAL);
        //printf("send success\n");
    }
    return 0;
}

int Rmdir(int netfd, char* addr,char *dirname)
{
    //printf("addr = %s\n",addr);
    int ret = rmdir(addr);
    train_t train;
    bzero(&train,sizeof(train));
    NETDESK_LOG_INFO(dirname,"rmdir");
    if(ret == -1)
    {
        sprintf(train.data,"rmdir: 删除\'%s\'失败: 没有那个文件或目录",dirname);
        train.length = strlen(train.data);
        send(netfd,&train,sizeof(int) + train.length,MSG_NOSIGNAL);
        NETDESK_LOG_DEBUG(dirname,"rmdir");

    }
    else 
    {
        send(netfd,&train,sizeof(int) + train.length,MSG_NOSIGNAL);
    }
    return 0;
}

int Remove(int netfd,char *addr,char *dirname)
{
    int ret = unlink(addr);
    train_t train;
    bzero(&train,sizeof(train));
    NETDESK_LOG_INFO(dirname,"remove");
    if(ret == -1)
    {
        sprintf(train.data,"rm: 无法删除\'%s\':没有那个文件或目录",dirname);
        train.length = strlen(train.data);
        send(netfd,&train,sizeof(int) + train.length,MSG_NOSIGNAL);
        NETDESK_LOG_DEBUG(dirname,"remove");
    }
    else
    {
        send(netfd,&train,sizeof(int) + train.length,MSG_NOSIGNAL);

    }
    return 0;
}
